#include "UseThreads.h"
// This calss is separated the runner and library //
CUseThreads::CUseThreads(unsigned short CPU, unsigned short memory_):m_NUM_CPU(CPU)
{
  m_memory=memory_;
  InitAndRun();
}

CUseThreads::~CUseThreads(void)
{
}
void CUseThreads::InitAndRun( void )
{
  {
  scoped_timer timethis("#All Analysis");
  CGenThreads objThreaded(m_memory);
  //here we can change thread number
  objThreaded.SetNumberOfThreads(m_NUM_CPU);
  {
  scoped_timer timethis("#Fill DATA: ");
  objThreaded.FillData();
  }

  const char *analtype[]={/*"Display",*/ "do_parallel_on_ID", "do_parallel_on_SNAPS"};
  TSpecificFunctor<CGenThreads> specFuncA0(&objThreaded, &CGenThreads::Display);
  TSpecificFunctor<CGenThreads> specFuncA1(&objThreaded, &CGenThreads::do_parallel_on_ID);
  TSpecificFunctor<CGenThreads> specFuncA2(&objThreaded, &CGenThreads::do_parallel_on_SNAPS);

  // TFunctor* vAnalysisTable[] = { &specFuncA0, &specFuncA1, &specFuncA2 };
  TFunctor* vAnalysisTable[] = { /*&specFuncA0,*/ &specFuncA1/*, &specFuncA2*/ };
  for(unsigned short  i=0;i<sizeof(vAnalysisTable)/sizeof(TFunctor*);i++)
    {
      // vAnalysisTable[i]->Call("objThreaded::Display called!");        // via function "Call"
      for(m_NUM_CPU=0;m_NUM_CPU<22;m_NUM_CPU+=2)
      {
	scoped_timer timethis(analtype[i]);
	objThreaded.SetNumberOfThreads(m_NUM_CPU==0?1:m_NUM_CPU);
	//	objThreaded.parallel_do_RUN(vAnalysisTable[i],0,objThreaded.GetDataSize(),analtype[i]);        // via function "Run"	
	objThreaded.parallel_do_RUN(vAnalysisTable[i],0,objThreaded.GetDataSize());        // via function "Run"	
	
      }
      //      objThreaded.WriteData();
    }
  cout<<"#**********\n";
  }

}


